﻿using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Test
{
    [TestClass]
    public class OleDbUnitTest
    {
        [TestMethod]

        /*
         * I need to read files.
         * Files must have Attribute "copy always"
         * Files are copied to bin/Debug
         * 
         * 
         */
        public void HelloWorld()
        {
            String fileContent = "";
            using (StreamReader sr = new StreamReader("../../../Test/bin/Debug/TextFile1.txt"))
            {
                fileContent = sr.ReadToEnd();
            }

            Assert.AreEqual("Hello world", fileContent);
        }


        [TestMethod]
        public void listOfTablesXls()
        {
            String fileName = "../../../Test/bin/Debug/ExcelSheetnames.xls";
            using (System.Data.OleDb.OleDbConnection _con = Markus.OleDb.fileName2OleDbConnection(fileName))
            {
                _con.Open();

                List<String> tableList = Markus.OleDb.listOfTables(_con);

                Assert.AreEqual(4, tableList.Count);
                Assert.AreEqual("TabA", tableList[0]);
                Assert.AreEqual("TabB", tableList[1]); 
                Assert.AreEqual("Tap A 2003", tableList[2]);
                Assert.AreEqual("Tap B 2003", tableList[3]);

                _con.Close();
            }
        }


        [TestMethod]
        public void listOfTablesXlsx()
        {
            String fileName = "../../../Test/bin/Debug/ExcelSheetnames.xlsx";
            using (System.Data.OleDb.OleDbConnection _con = Markus.OleDb.fileName2OleDbConnection(fileName))
            {
                _con.Open();

                List<String> tableList = Markus.OleDb.listOfTables(_con);

                Assert.AreEqual(4, tableList.Count);
                Assert.AreEqual("TabA", tableList[0]);
                Assert.AreEqual("TabB", tableList[1]);
                Assert.AreEqual("Tap A 2007", tableList[2]);
                Assert.AreEqual("Tap B 2007", tableList[3]);

                _con.Close();
            }
        }


        [TestMethod]
        public void listOfTables_input_null()
        {
            System.Data.OleDb.OleDbConnection _con = null;
            List<String> los = Markus.OleDb.listOfTables(_con);
            Assert.AreEqual(los.Count(), 0);
        }
    }
}
